package com.zx.mes.rabbitmq.api.hyl.api.returnlistener;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * confirm topic test
 *
 * @author huayunlong
 * @date 2018-9-4
 */
public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername("admin");
        factory.setPassword("123456");
        factory.setHost("10.30.90.136");
        factory.setPort(5672);
        factory.setVirtualHost("/");

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.basicPublish("test.topic", "test.add", null, "神不在的星期天topic add!".getBytes());

        channel.addReturnListener((replyCode, replyText, exchange, routingKey, properties, body) -> {
            System.out.println("replyCode:["+replyCode+"] replyText:["+replyText+"]");
        });

        /// 关闭取消掉等待ack
//        channel.close();
//        connection.close();

    }
}
